"""
功能描述：


类
    初始化方法
    
    实例化方法
    
"""

def variable_learn():
    # class int
    a = 1
    print(type(a))

    # class str
    b = 's'
    print(type(b))

    # class float
    c = 1.1
    print(type(c))

    # class bool
    d = True
    print(type(d))

    # class list
    e = [1,2,3]
    print(type(e))

    # class set
    f = {1,2,3}
    print(type(f))

    # class tuple
    g = (1,2,3)
    print(type(g))

    # class dict
    h = {1:2,3:4}


def str_learn():
    # 切片, 下标从0开始，[开始：结束：步长],顾头不顾尾 如下标4, 实际输出不含当前字符
    a = 'abcdefg'
    print(a[1:3])
    print(a[:4:])
    print(a[1::2])  # 从第二个字符开始，步长为2, 输出 b d f
    print(a[::-1]) #从0开始，到最后结束，步长为-1, 输出 gfedcba
    print(a[5:1:-1]) # 从下标5开始，到下标1结束，步长为-1, 输出 fedc
    print(a[-1:-5:-1])  # 从下标-1开始，到下标-5结束 不含-5当前下标元素，步长为-1, 输出 gfed
    print(a[-1:-5:1],"test")  # 从下标-1开始，到-5结束，步长为1，但步长是从左往右数，所以下标-1是字符串最后一个元素，往右没有元素，输出为空
    print(a[-5:-1:1])
    print(a[2:6:1])


def str_find():
    a = 'abcdefg'
    mystr = "hello world and supertest and chenghao and Python"

    s = a.find('c')
    print(s)
    # 返回字符串中第一个匹配项的索引 下标0开始
    print(mystr.find('and'))
    # 找不到返回-1
    print(mystr.find('asdf'))
    # 从指定位置开始查找,从13开始
    print(mystr.find('and',13))
    # 从下标13开始，到15结束
    print(mystr.find('and',13,15))
    # 从右往左查找
    print(mystr.rfind('and'))
    print(mystr.find('and',27))
    print(a.rfind('de'))
    print(a[0],a[1],a[2],a[3])


    print('---------------')

    print(a.index('b'))
    print(mystr.index('nd'))
    print(mystr.index('and',13))
    # 找不到返回报错
    # print(mystr.index('andf',13,15))

    print('---------------')
    str1 = 'asdfghjkl,aa,.s'
    # 统计字符串中某个字符出现的次数
    print(str1.count('s'))
    print(str1.count('s',3,199))
    print(len(str1))
    print(str1.count('s',3,len(str1)))


def str_replace():
    str1 = 'asdfghjkl'
    # 替换字符串中某个字符
    new_str = str1.replace('s','hello')
    print(new_str)
    print(str1.replace('a','world'))

    s2 = 'abacdeafgahiajk'
    new2 = s2.replace('a',' test ',5)
    new3 = s2.replace('a',' hello ',2)
    print(new2)
    print(new3)
    print(s2.replace('a',' hello ',-1))

    print(s2)

def str_split():
    list1 = ['chao', 'ge', 'test', 'promotion']
    # 字符串拼接,输出结果是字符串
    print(type("-".join(list1)))
    tuple1 = ('chao', 'ge', 'test', 'promotion')
    print('.'.join(tuple1))



if __name__ == '__main__':
    # variable_learn()
    # str_learn()
    # str_find()
    # str_replace()
    str_split()
